package com.qwz.example.itreator.impl;

import com.qwz.example.itreator.Aggregate;
import com.qwz.example.itreator.Iterator;
import com.qwz.example.model.PayModel;

import java.util.ArrayList;
import java.util.List;

/**
* @Description: 客户方已有的工资管理对象
* @Package com.qwz.example.PayManager
* @author Qiuwuzhi
* @date 2019/12/26 15:16
* @version V1.0
*/
public class PayManager extends Aggregate {
    /**
     * 聚合对象，这里是java的集合对象
     */
    private List list = new ArrayList();

    /**
     * 获取工资列表
     * @return
     */
    public List getList() {
        return list;
    }

    /**
     * 计算工资
     */
    public void calcPay(){
        PayModel model1 = new PayModel();
        model1.setPay(3000);
        model1.setUserName("zs");

        PayModel model2 = new PayModel();
        model2.setPay(2000);
        model2.setUserName("ls");

        list.add(model1);
        list.add(model2);
    }

    @Override
    public Iterator createIterator() {
        return new CollectionIteratorImpl(this);
    }

    public Object get(int index){
        Object retObj = null;
        if (index<list.size()){
            retObj = list.get(index);
        }
        return retObj;
    }

    public int size(){
        return this.list.size();
    }
}
